import Vue from 'vue'
import Vuex from 'vuex'
import createPersistedState from "vuex-persistedstate"
Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    token: '',
    auth_code: '',//授权码
    // keepAliveRouter: ['Home', 'piano'],
    avatar: '',
    idx: " -1",
    is_sign: []
    // examInfo: [],
  },
  mutations: {
    // token存储
    setToken(state, val) {
      state.token = val[0]
      state.auth_code = val[1]
    },
    // index
    saveIndx(state, val) {
      state.idx = val
    },
    // 签名存储
    saveSign(state, val) {
      state.is_sign = val
    },
    // 缓存组件
    keepRouter(state, val) {
      state.keepAliveRouter = val
    },
    // 照片存储
    saveImage(state, val) {
      state.avatar = val
    }
  },
  actions: {
  },
  modules: {
  },
  plugins: [createPersistedState({
    reducer(val) {
      return {
        token: val.token,
        auth_code: val.auth_code,
        keepAliveRouter: val.keepAliveRouter,
        avatar: val.avatar,
        idx: val.idx
        // examInfo: val.examInfo
      }
    }
  })]
})
